// pages/diangu/diangu.js
var api = require('../../utils/api.js');



Page({


  data: {
    list: [],
    pageIndex: 1,
    pageSize: 20,
    content: "",
    showPopup: false,
    isHideLoadMore: true
  },



  onLoad: function (options) {
    var that = this;
    loadData(that, function (list) {
      that.setData({ list: list });
    });
  },

  onReachBottom: function () {
    var that = this;
    that.setData({
      pageIndex: that.data.pageIndex + 1,
      isHideLoadMore: false
    });
    loadData(that, function (list) {
      that.setData({
        list: that.data.list.concat(list),
        isHideLoadMore: true
      });
    });
  },

  togglePopup() {
    this.setData({
      showPopup: !this.data.showPopup
    });
  },

  show: function (e) {
    console.log("show", e);
    for (var i = 0; i < this.data.list.length; i++) {
      if (this.data.list[i].id == e.target.dataset.lid) {
        this.setData({
          content: this.data.list[i].content
        });
      }
    }
    this.setData({
      showPopup: !this.data.showPopup
    });
  }


})

function loadData(that, fun) {
  api.loadArticles('dgs', that.data.pageIndex, that.data.pageSize, function (list, count) {
    fun(list);
  });
}
